// 导入 request 模块
import request from "@/utils/request.js";

// 登录
export const userLoginService = (UserData)  => {
  return request.post('users/login', UserData)
}
// 注册
export const userRegisterService = (UserData)  => {
  return request.post('users/register', UserData)
}
// 获取用户信息
export const userInfoService = ()  => {
  return request.get('users/info')
}  

// 上传文件
export const uploadFileService = (file) => {
  // 创建 FormData 对象
  let formData = new FormData()
  // 添加文件
  formData.append('file', file)
  // 发送请求
  return request.post('users/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取用户类型
export const userTypeService = () => {
  return request.get('/users/type')
}

// 根据id获取用户类型
export const userTypeByIdService = (id) => {
  return request.get(`/users/type/${id}`)
}

// 获取分页用户列表
export const userPageService = (pageQuery) => {
  return request.get('/users/page', { params: pageQuery })
}

// 根据id删除用户
export const userDeleteByIdService = (id) => {
  return request.delete(`/users/${id}`)
}

// 更改用户基础信息
export const userUpdateService = (data) => {
  return request.put('/users', data)
}

// 更新用户详细信息
export const userInfoUpdateService = (data) => {
  return request.put('/users/info', data)
}

// 获取用户详细信息
export const userByIdService = (id) => {
  return request.get(`/users/${id}`)
}

// 添加用户
export const userAddService = (UserData) => {
  console.log(UserData);
  return request.post('/users', UserData)
}

// 获取角色权限
export const userRoleService = () => {
  return request.get('/users/user_role')
}

// 更新角色权限
export const userRoleUpdateService = (data) => {
  return request.put('/users/user_role', data)
}

// 根据id获取角色权限
export const userRoleByIdService = (id) => {
  return request.get(`/users/user_role/${id}`)
}

// 获取角色分页列表
export const rolePageService = (pageQuery) => {
  return request.get('/users/role/page', { params: pageQuery })
}

// 跟新角色权限
export const roleUpdateService = (data) => {
  return request.put('/users/role', data)
}

// 通过id获取角色权限
export const roleByIdService = (id) => {
  return request.get(`/users/role/${id}`)
}

// 添加角色权限
export const roleAddService = (data) => {
  return request.post('/users/role', data)
}

// 删除角色权限
export const roleDeleteByIdService = (id) => {
  return request.delete(`/users/role/${id}`)
}

// 获取菜单列表
export const menuListService = () => {
  return request.get('/users/menu/list')
}

// 根据id获取菜单信息
export const menuByIdService = (id) => {
  return request.get(`/users/menu/${id}`)
}

// 添加菜单
export const menuAddService = (data) => {
  return request.post('/users/menu', data)
}

// 修改菜单
export const menuUpdateService = (data) => {
  return request.put('/users/menu', data)
}

// 删除菜单
export const menuDeleteService = (id) => {
  return request.delete(`/users/menu/${id}`)
}

// 根据角色id更改权限json
export const roleUpdateAssignmentService = (data) => {
  return request.put('/users/role/assignment', data)
}

// 根据角色id获取权限json
export const roleQueryAssignmentService = (id) => {
  return request.get(`/users/role/assignment/${id}`)
}